Page({
  data: {
    title: '',
    scoreText: '',
    levelText: '',
    interpretation: ''
  },
  onLoad(options) {
    // 1. 通过参数传递
    let result = {};
    if (options.type) {
      result = this.parseResultFromOptions(options);
    } else {
      // 2. 或通过storage
      result = wx.getStorageSync('test_result') || {};
    }
    this.setData(result);
  },
  parseResultFromOptions(options) {
    // 适配不同测试类型
    const type = options.type;
    let title = '';
    let scoreText = '';
    let levelText = '';
    let interpretation = decodeURIComponent(options.interpretation || '');

    if (type === 'sas') {
      title = 'SAS 测试结果';
      scoreText = '你的标准分：' + options.standard_score;
      levelText = (options.anxiety_level || '') + '：';
    } else if (type === 'sds') {
      title = 'SDS 测试结果';
      scoreText = '你的标准分：' + options.standard_score;
      levelText = (options.depression_level || '') + '：';
    } else if (type === 'mbti') {
      title = 'MBTI 测试结果';
      scoreText = '你的类型：' + (options.mbti_type || '');
      levelText = '';
    } else if (type === 'baker') {
      title = '贝克抑郁测试结果';
      scoreText = '你的总分：' + options.total_score;
      levelText = (options.depression_level || '') + '：';
    } else {
      title = '测试结果';
      scoreText = '';
      levelText = '';
    }
    return { title, scoreText, levelText, interpretation };
  },
  onFinish() {
    wx.switchTab({
      url: '/pages/index/index'
    });
  }
});